package org.jeecg.modules.paycenter.service;

import com.alibaba.fastjson.JSON;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.paycenter.enums.BillTypeEnum;
import org.jeecg.modules.paycenter.dto.PayBillData;
import org.jeecg.modules.wlhy.bill.entity.HyBill;
import org.jeecg.modules.wlhy.bill.entity.HyCustomerBill;
import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
import org.jeecg.modules.wlhy.bill.service.IHyBillService;
import org.jeecg.modules.wlhy.bill.service.IHyCustomerBillService;
import org.jeecg.modules.wlhy.bill.service.IHyShippingNoteBillService;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.service.IHyDfFeeService;
import org.jeecg.modules.wlhy.hyplatform.service.IHyPlatformCostService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: 支付功能基类
 */
public abstract class BasePayChannelService implements IPayChannelService {

    @Autowired protected IHyPlatformCostService hyPlatformCostService;
    @Autowired protected BillService    billService;
    @Autowired protected IHyBillService hyBillService;
    @Autowired protected IHyDfFeeService hyDfFeeService;

    @Autowired protected IHyShippingNoteBillService hyShippingNoteBillService;
    @Autowired protected IHyCustomerBillService hyCustomerBillService;

    @Autowired
    protected PayUtil payUtil;

    //region 默认实现
    @Override
    public Result<?> batchDownloadShippingBillHd(List<HyShippingNoteBill> shippingNoteBills){
        return Result.error("操作不可用,不支持此功能");
    }

    @Override
    public Result<?> batchDownloadCustomerBilHd(List<HyCustomerBill> customerBills){
        return Result.error("操作不可用,不支持此功能");
    }
    //endregion

    //region 支付默认实现

    @Override
    public Result<?> billPayBatch(List<HyBill> hyBills, HyCustomer customer) {
        return Result.error("操作不可用,不支持此功能");
    }

    @Override
    public Result<?> billPlateformPay(List<HyBill> hyBills, HyCustomer customer) {
        return Result.error("操作不可用,不支持此功能");
    }

    @Override
    public Result<?> billRePayBatch(List<HyBill> hyBills, HyCustomer customer) {
        return Result.error("操作不可用,不支持此功能");
    }

    @Override
    public Result<?> agentDianFuPayBatch(BillTypeEnum billTypeEnum, List<HyBill> hyBills, HyCustomer agent, HyCustomer customer) {
        return Result.error("操作不可用,不支持此功能");
    }
    //endregion

    //region 提交支付 消息队列
    public void billPay(HyBill hyBill) {
        try {
            payUtil.billPay(hyBill.getId());
        } catch (Exception e) {
            hyBill.setPayStatus("7");
            hyBill.setBillPayRemark(e.getMessage());
            hyBillService.updateById(hyBill);
        }
    }

    public void billPayBatch(List<HyBill> bills) {
        for (HyBill bill : bills) {
            this.billPay(bill);
        }
    }
    //endregion

}
